package num190;

/**
 * 190. 颠倒二进制位
 * 题目：https://leetcode-cn.com/problems/reverse-bits/
 * 三叶姐题解: https://leetcode-cn.com/problems/reverse-bits/solution/yi-ti-san-jie-dui-cheng-wei-zhu-wei-fen-ub1hi/
 * 三叶姐
 *
 * 「逐位分离」构造
 */
public class Solution2 {
    public int reverseBits(int n) {
        int ans = 0;
        int cnt = 32;
        while (cnt-- > 0) {
            ans <<= 1;
            ans += (n & 1);
            n >>= 1;
        }
        return ans;
    }
}
